let app = getApp();
import { getShop } from "../../../request/api";
let iconUrl = 'https://atush.vip/static/icons/';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lang: null,
        filter_hidden_box: false,
        filter_hidden_box_animation: false,
        box: [],
        filterShop: [
            {id: 1, name: 'dinningRoom', icon: iconUrl +'canting.svg'},
            {id: 2, name: 'supermarket', icon: iconUrl +'chaoshi.svg'},
            {id: 3, name: 'dessert', icon: iconUrl +'tianping.svg'},
            {id: 4, name: 'clothing', icon: iconUrl +'fuzhuang.svg'},
            {id: 5, name: 'hotPot', icon: iconUrl +'huoguo.svg'},
            {id: 6, name: 'repair', icon: iconUrl +'weixiu.svg'},
            {id: 7, name: 'billiards', icon: iconUrl +'billiards.svg'},
            {id: 8, name: 'all', icon: iconUrl + 'quanbu.svg'},
        ],
        filterShop_all: [
            {id: 1, name: 'dinningRoom', icon: iconUrl +'canting.svg'},
            {id: 2, name: 'supermarket', icon: iconUrl +'chaoshi.svg'},
            {id: 3, name: 'dessert', icon: iconUrl +'tianping.svg'},
            {id: 4, name: 'clothing', icon: iconUrl +'fuzhuang.svg'},
            {id: 5, name: 'altun', icon: iconUrl +'goldShop.svg'},
            {id: 6, name: 'hotPot', icon: iconUrl +'huoguo.svg'},
            {id: 7, name: 'repair', icon: iconUrl +'weixiu.svg'},
            {id: 8, name: 'billiards', icon: iconUrl +'billiards.svg'},
            {id: 9, name: 'flowers', icon: iconUrl +'flowers.svg'},
            {id: 10, name: 'makeup', icon: iconUrl +'makeup.svg'},
            {id: 11, name: 'photography', icon: iconUrl +'photography.svg'},
            {id: 12, name: 'xiche', icon: iconUrl +'xiche.svg'},
            {id: 13, name: 'haircut', icon: iconUrl +'chuifengji.svg'},
            {id: 14, name: 'dujiacun', icon: iconUrl +'dujiacun.svg'},
            {id: 15, name: 'yangsheng', icon: iconUrl +'yangsheng.svg'},
            {id: 16, name: 'real_estate', icon: iconUrl +'yumilakOy.svg'},
        ],

        // 分页
        pageNo: 1,
        totalPage: 0,
    },

    // my function

    // 筛选店铺
    onCilckShopFilter(item) {
        let filterId = item.currentTarget.dataset.item.id
        let filterType = null
        switch (filterId) {
            case 1:
                filterType = 25
                break;
            case 2:
                filterType = 26
                break;
            case 3:
                filterType = 27
                break;
            case 4:
                filterType = 28
                break;
            case 5:
                filterType = 37
                break;
            case 6:
                filterType = 38
                break;
            case 7:
                filterType = 39
                break;
            case 8:
                // 打开更多筛选店铺
                return this.shopMore()
            default:
                break;
        }
        wx.navigateTo({
            url: '/pages/home/shop/filterShop/filterShop?filterType=' + filterType
        });
    },

    // 从筛选全部店铺列表
    onCilckAllShopFilter(item) {
        let filterId = item.currentTarget.dataset.item.id
        let filterType = null
        switch (filterId) {
            case 1:
                filterType = 25
                break;
            case 2:
                filterType = 26
                break;
            case 3:
                filterType = 27
                break;
            case 4:
                filterType = 28
                break;
            case 5:
                filterType = 36
                break;
            case 6:
                filterType = 37
                break;
            case 7:
                filterType = 38
                break;
            case 8:
                filterType = 39
                break;
            case 9:
                filterType = 40
                break;
            case 10:
                filterType = 41
                break;
            case 11:
                filterType = 42
                break;
            case 12:
                filterType = 43
                break;
            case 13:
                filterType = 44
                break;
            case 14:
                filterType = 45
                break;
            case 15:
                filterType = 46
                break;
            case 16:
                filterType = 47
                break;
            default:
                break;
        }
        wx.navigateTo({
            url: '/pages/home/shop/filterShop/filterShop?filterType=' + filterType
        });
        let that = this;
        setTimeout(function() {
            that.setData({ filter_hidden_box_animation: true, filter_hidden_box: false })
        }, 2000)
    },

    // 灰色页面点击
    shopPageMask() {
        let that = this;
        this.setData({ filter_hidden_box_animation: true, filter_hidden_box: false })
        // setTimeout(function () {
            // that.setData({ filter_hidden_box: false })
        // }, 1000)
    },

    // 打开更多筛选店铺
    shopMore() {
        if(!this.data.filter_hidden_box) {
            this.setData({ filter_hidden_box: true, filter_hidden_box_animation: false })
        }
    },

    // 获取内容
    getPost() {
        let status = 1
        let data = { status, pageNo : this.data.pageNo }
        getShop(res => {
            if (res.statusCode == 200) {
                this.setData({ box: this.data.box.concat(res.data.data), totalPage : res.data.totalPage })
            }
        }, data);
    },

    // 往详细页面
    goDetailed(event) {
        let itemId = event.currentTarget.dataset.item.id
        wx.navigateTo({
            url: '/pages/home/shop/shopDetailed/shopDetailed?itemId=' + itemId
        });
    },

    // App 默认方法

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({ lang: app.globalData.lang, navTitle: "shopInfo", navigation: true })
        this.getPost()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.pageNo == this.data.totalPage) return
        let pageNo = this.data.pageNo += 1
        this.setData({pageNo : pageNo})
        this.getPost();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})